package pl.hexar.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "USERS")
@NamedQueries( {
		@NamedQuery(name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login=:login"),
		@NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email=:email") })
public class User implements Serializable {
	private long id;
	private String login;
	private String email;
	private String password;
	private Date regDate;
	private Date lastLogDate;

	public User(String login, String email, String password, Date regDate) {
		this.login = login;
		this.email = email;
		this.password = password;
		this.regDate = regDate;
	}

	public User() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(unique = true, length = 30)
	@Length(min = 5, max = 30)
	@NotNull
	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	@Email
	@Column(length = 50, unique = true)
	@Length(min = 5, max = 50)
	@NotNull
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(length = 40)
	@Length(min = 5, max = 40)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public Date getLastLogDate() {
		return lastLogDate;
	}

	public void setLastLogDate(Date lastLogDate) {
		this.lastLogDate = lastLogDate;
	}

}
